package com.it.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.it.entity.PageResult;
import com.it.pojo.CheckItem;
import com.it.dao.CheckItemDao;
import com.it.service.CheckItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 检查项服务
 */
@Service(interfaceClass = CheckItemService.class)
@Transactional
public class CheckItemServiceImpl implements CheckItemService {

    @Autowired
    private CheckItemDao checkItemDao;
    //新增
    public void add(CheckItem checkItem) {
        checkItemDao.add(checkItem);
    }

    //查询
    public PageResult pageQuery(Integer currentPage,Integer pageSize,String queryString){

        PageHelper.startPage(currentPage,pageSize);
        Page<CheckItem> page = checkItemDao.selectByCondition(queryString);
        return new PageResult(page.getTotal(),page.getResult());

    }

    //删除检查项
    public void deleteById(Integer id){

        long count = checkItemDao.findCountByCheckItemId(id);
        if (count >0){
            throw new RuntimeException("当前检查项被引用不允许删除");

        }
        checkItemDao.deleteById(id);

    }

    public CheckItem findById(Integer id){
        return checkItemDao.findById(id);

    }

    public void edit(CheckItem checkItem){
        checkItemDao.edit(checkItem);

    }
    public List<CheckItem> findAll(){
        return checkItemDao.findAll();
    }


}